<template>
    <div class="apply">
        <el-tabs v-model="activeName" @tab-click="handleClick">
            <el-tab-pane label="贫困户申请" name="first">
                <div class="content">
                    <ApplyTable :type="form.type" :applyArr="applyArr" @getApplyData="getApplyData"></ApplyTable>
                </div>
            </el-tab-pane>
            <el-tab-pane label="扶贫项目申请" name="second">
                <div class="content">
                    <ApplyTable :type="form.type" :applyArr="applyArr" @getApplyData="getApplyData"></ApplyTable>
                </div>
            </el-tab-pane>
        </el-tabs>
        <Dialog :type="this.form.type" @getApplyData="getApplyData"></Dialog>
    </div>
</template>
<script>
import { mapState } from 'vuex';
import ApplyTable from './apply_table/index.vue'
import Dialog from './dialog/index.vue'
export default {
    name: 'Apply',
    components: {
        ApplyTable,
        Dialog
    },
    mixins: [],
    props: {

    },
    data() {
        return {
            activeName: 'first',
            applyArr: [],
            form: {
                type: 0,
                currentPage: 1,
                pageSize: 10
            }
        }
    },
    computed: {
        ...mapState('userStore', ['userInfo']),
        ...mapState('paginationStore', ['currentPage', 'pageSize'])

    },
    watch: {

    },
    mounted() {
        this.getApplyData(this.form)

    },
    methods: {
        handleClick(tab, event) {
            this.form.type = tab.index
            this.getApplyData(this.form)
        },
        getApplyData(form = {
            type: 0,
            currentPage: 1,
            pageSize: 10
        }) {
            if (this.form.type == 0) {
                this.request.post('/poorApplyInfo/selectApplyInfoPage', form).then(res => {
                    if (res.code == 20000) {
                        // 审核状态 0-待审核，1-审核通过，2-审核不通过，3-已取消
                        res.data.list.filter(item => item.userId === this.userInfo.userId).forEach(item => {
                            if (item.reviewStatus === 0) {
                                item.reviewStatus = '待审核'
                            } else if (item.reviewStatus === 1) {
                                item.reviewStatus = '审核通过'
                            } else if (item.reviewStatus === 2) {
                                item.reviewStatus = '审核不通过'
                            } else if (item.reviewStatus === 3) {
                                item.reviewStatus = '已撤销申请'
                            }
                        })
                        res.data.list.forEach(item => {
                            if (item.createdDt) {
                                let font = item.createdDt.slice(0, 10)
                                let after = item.createdDt.slice(11)
                                item.createdDt = font + ' ' + after
                            }
                        })
                        this.applyArr = res.data
                    }
                })
            } else if (this.form.type == 1) {
                this.request.post('/projectApplyInfo/selectApplyInfoPage', form).then(res => {
                    if (res.code == 20000) {
                        // 审核状态 0-待审核，1-审核通过，2-审核不通过，3-已取消
                        res.data.list.filter(item => item.userId === this.userInfo.userId).forEach(item => {
                            if (item.reviewStatus === 0) {
                                item.reviewStatus = '待审核'
                            } else if (item.reviewStatus === 1) {
                                item.reviewStatus = '审核通过'
                            } else if (item.reviewStatus === 2) {
                                item.reviewStatus = '审核不通过'
                            } else if (item.reviewStatus === 3) {
                                item.reviewStatus = '已撤销申请'
                            }
                        })
                        this.applyArr = res.data
                    }
                })
            }
            // /projectApplyInfo/selectApplyInfoPage
        },
        editAndAdd(obj) {
            if (this.type == 0) {
                this.request.post('/poorApplyInfo/orderAdit', obj).then(res => {
                    if (res.code == 20000) {
                        this.$emit('getApplyData')
                    }
                })
            } else if (this.type == 1) {
                this.request.post('/projectApplyInfo/orderAdit', obj).then(res => {
                    if (res.code == 20000) {
                        this.$emit('getApplyData')
                    }
                })
            }
        }
    }
};
</script>
<style lang='less' scoped>
.apply {
    width: 80%;
    margin: 0 auto;

    .content {
        overflow-y: auto;
    }

}
</style>